package cn.wiseda.finance.dao.util;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

public class AdvancedJdbcBasicDao extends NamedParameterJdbcTemplate {

    public AdvancedJdbcBasicDao(DataSource dataSource) {
        super(dataSource);
    }

    public boolean update(String sql, Object object) {
        SqlParameterSource paramSource = new BeanPropertySqlParameterSource(object);
        int update = update(sql, paramSource);
        return update > 0 ? true : false;
    }

    public <T> List<T> query(String sql, Object object, Class<T> clazz) {
        BeanPropertyRowMapper<T> rowMapper = new BeanPropertyRowMapper<>(clazz);
        SqlParameterSource paramSource = new BeanPropertySqlParameterSource(object);
        
        List<T> list = query(sql, paramSource, rowMapper);
        return list;
    }
    
    
}
